<template>
  <div>


    <el-row>
      <el-button-group>
        <el-button type="info" :size='size' @click="addShow" :disabled="toggleShow">新增</el-button>
        <el-button type="info" :size='size' @click="editShow" :disabled="!toggleShow">修改</el-button>



      </el-button-group>
      <!-- 修改下拉框 -->
      <template v-if="!toggleShow">
        <el-select style="margin-left: 1.25rem;" @change="editChange" :size="size" v-model="value" placeholder="请选择客户名称">
          <el-option v-for="item in options" :key="item.id" :label="item.customerName" :value="item.id">
          </el-option>
        </el-select>
      </template>
      <el-button :size="size" icon="el-icon-close" @click="qingkong" v-if="!toggleShow" circle></el-button>
    </el-row>
    <!-- 修改 -->
    <el-row v-if="!toggleShow">
      <el-divider></el-divider>
      <span v-if="!value">请选择二网公司名称</span>
      <!-- 根据下拉框是否有值 显示 -->
      <br />
      <div v-if="value">
        <el-form ref="form1" :inline="true" :rules="rules" :model="form" label-width="120px">
          <div>
            <el-form-item label="日期:" prop="date">
              <el-date-picker :size="size" disabled style="width: 90%;" v-model="form.date" type="datetime">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="部门:" prop="dept">
              <el-input :size="size" disabled v-model="form.dept"></el-input>
            </el-form-item>
            <el-form-item label="职位:" prop="zhiwei">
              <el-input :size="size" disabled v-model="form.zhiwei"></el-input>
            </el-form-item>
            <el-form-item label="接洽人员:" prop="zhiwei">
              <el-input :size="size" disabled v-model="form.name"></el-input>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="客户姓名:" prop="customerName">
              <el-input :size="size" v-model="form.customerName" placeholder="请填写客户姓名"></el-input>
            </el-form-item>
            <el-form-item style="margin-left: 15px;" label="客户性别:" prop="customerSex">
              <el-select :size="size" v-model="form.customerSex" placeholder="请选择客户性别">
                <el-option v-for="item in customerSex" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="区域:" prop="area">
              <el-select :size="size" v-model="form.area" placeholder="请选择区域">
                <el-option v-for="item in area" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="联系电话:" prop="phone">
              <el-input :size="size" v-model="form.phone" placeholder="请填写电话号码"></el-input>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="微信号:" prop="weiXin">
              <el-input :size="size" v-model="form.weiXin" placeholder="请填写客户微信号"></el-input>
            </el-form-item>
            <el-form-item label="客户职业:" prop="customerZhiwei">
              <el-input :size="size" v-model="form.customerZhiwei" placeholder="请填写客户职业"></el-input>
            </el-form-item>
            <el-form-item label="接洽方式:" prop="jieQia">
              <el-select :size="size" v-model="form.jieQia" placeholder="请选择接洽方式">
                <el-option v-for="item in jieQia" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="获客途径:" prop="huoKeTuJing">
              <el-select  :size="size" v-model="form.huoKeTuJing" placeholder="请选择获客途径">
                <el-option v-for="item in huoKeTuJing" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="拟购车型:" prop="cars">
              <el-select :size="size" v-if="showTree" clearable v-model="form.cars" multiple collapse-tags style="width: 100%;"
                placeholder="请选择拟购车型">
                <el-option v-for="item in cars" :key="item.value" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="身份证号:" prop="idCard">
              <el-input :size="size" v-model="form.idCard" placeholder="请填写身份证号"></el-input>
            </el-form-item>
            <el-form-item label="试驾车型:" prop="cars2">
              <el-select :size="size" v-if="showTree" clearable v-model="form.cars2" multiple collapse-tags style="width: 100%;"
                placeholder="请选择试驾车型">
                <el-option v-for="item in cars" :key="item.value" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="试乘感觉:" prop="feel">
              <el-select :size="size" v-model="form.feel" placeholder="请选择客户试乘感觉">
                <el-option v-for="item in feel" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="试乘次数:" prop="number">
              <el-select :size="size" v-model="form.number" placeholder="请选择客户试乘次数">
                <el-option v-for="item in number" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="到店次数:" prop="reachStore">
              <el-select :size="size" v-model="form.reachStore" placeholder="请选择客户到店次数">
                <el-option v-for="item in reachStore" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="跟进次数:" prop="followNum">
              <el-select :size="size" v-model="form.followNum" placeholder="请选择跟进次数">
                <el-option v-for="item in followNum" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="跟进意向级别:" prop="followRank">
              <el-select :size="size" v-model="form.followRank" placeholder="请选择跟进意向级别">
                <el-option v-for="item in followRank" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="客户状况:" prop="customerState">
              <el-select :size="size" v-model="form.customerState" placeholder="请选择客户状况">
                <el-option v-for="item in customerState" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="预计付款方式:" prop="payment">
              <el-select :size="size" v-model="form.payment" placeholder="请选择客户预计付款方式">
                <el-option v-for="item in payment" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="置换意向:" prop="zhiHuan">
              <el-select :size="size" v-model="form.zhiHuan" placeholder="请选择置换意向">
                <el-option v-for="item in zhiHuan" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>

          </div>
        </el-form>
        <el-divider></el-divider>
        <el-button type="primary" style="float: right;" :size='size' @click="save">保存</el-button>
      </div>
    </el-row>


    <!-- 新增 -->
    <el-row v-if="toggleShow">
      <el-divider></el-divider>
      <!-- 改成行类表单  :inline="true"  -->
      <el-form ref="form1" :inline="true" :rules="rules" :model="form" label-width="90px">

        <!-- 用br换行 或者div  -->

        <div>
          <el-form-item label="日期:" prop="date">
            <el-date-picker :size="size" disabled style="width: 90%;" v-model="form.date" type="datetime">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="部门:" prop="dept">
            <el-input :size="size" disabled v-model="form.dept"></el-input>
          </el-form-item>
          <el-form-item label="职位:" prop="zhiwei">
            <el-input :size="size" disabled v-model="form.zhiwei"></el-input>
          </el-form-item>
          <el-form-item label="接洽人员:" prop="zhiwei">
            <el-input :size="size" disabled v-model="form.name"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="客户姓名:" prop="customerName">
            <el-input :size="size" v-model="form.customerName" placeholder="请填写客户姓名"></el-input>
          </el-form-item>
          <el-form-item style="margin-left: 15px;" label="客户性别:" prop="customerSex">
            <el-select :size="size" v-model="form.customerSex" placeholder="请选择客户性别">
              <el-option v-for="item in customerSex" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="区域:" prop="area">
            <el-select :size="size" v-model="form.area" placeholder="请选择区域">
              <el-option v-for="item in area" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="联系电话:" prop="phone">
            <el-input :size="size" v-model="form.phone" placeholder="请填写电话号码"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="微信号:" prop="weiXin">
            <el-input :size="size" v-model="form.weiXin" placeholder="请填写客户微信号"></el-input>
          </el-form-item>
          <el-form-item label="客户职业:" prop="customerZhiwei">
            <el-input :size="size" v-model="form.customerZhiwei" placeholder="请填写客户职业"></el-input>
          </el-form-item>
          <el-form-item label="接洽方式:" prop="jieQia">
            <el-select :size="size" v-model="form.jieQia" placeholder="请选择接洽方式">
              <el-option v-for="item in jieQia" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="获客途径:" prop="huoKeTuJing">
            <el-select :size="size" v-model="form.huoKeTuJing" placeholder="请选择获客途径">
              <el-option v-for="item in huoKeTuJing" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item v-if="!ershou" label="拟购车型:" prop="cars">
            <el-select :size="size" v-if="showTree" clearable v-model="form.cars" multiple collapse-tags style="width: 100%;"
              placeholder="请选择拟购车型">
              <el-option v-for="item in cars" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="ershou" label="拟购车型:" prop="oldcars2">
            <el-select :size="size" v-if="showTree" clearable v-model="form.oldcars2" multiple collapse-tags style="width: 100%;"
              placeholder="请选择拟购车型">
              <el-option v-for="item in cars" :key="item.value" :label="item.esccxmc" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="身份证号:" prop="idCard">
            <el-input :size="size" v-model="form.idCard" placeholder="请填写身份证号"></el-input>
          </el-form-item>
          <el-form-item v-if="!ershou" label="试驾车型:" prop="cars2">
            <el-select :size="size" v-if="showTree" clearable v-model="form.cars2" multiple collapse-tags style="width: 100%;"
              placeholder="请选择试驾车型">
              <el-option v-for="item in cars" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="ershou" label="试驾车型:" prop="oldcars1">
            <el-select :size="size" v-if="showTree" clearable v-model="form.oldcars1" multiple collapse-tags style="width: 100%;"
              placeholder="请选择试驾车型">
              <el-option v-for="item in cars" :key="item.value" :label="item.esccxmc" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="试乘感觉:" prop="feel">
            <el-select :size="size" v-model="form.feel" placeholder="请选择客户试乘感觉">
              <el-option v-for="item in feel" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="试乘次数:" prop="number">
            <el-select :size="size" v-model="form.number" placeholder="请选择客户试乘次数">
              <el-option v-for="item in number" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="到店次数:" prop="reachStore">
            <el-select :size="size" v-model="form.reachStore" placeholder="请选择客户到店次数">
              <el-option v-for="item in reachStore" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="跟进次数:" prop="followNum">
            <el-select :size="size" v-model="form.followNum" placeholder="请选择跟进次数">
              <el-option v-for="item in followNum" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="跟进意向级别:" prop="followRank">
            <el-select :size="size" v-model="form.followRank" placeholder="请选择跟进意向级别">
              <el-option v-for="item in followRank" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="客户状况:" prop="customerState">
            <el-select :size="size" v-model="form.customerState" placeholder="请选择客户状况">
              <el-option v-for="item in customerState" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="预计付款方式:" prop="payment">
            <el-select :size="size" v-model="form.payment" placeholder="请选择客户预计付款方式">
              <el-option v-for="item in payment" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="置换意向:" prop="zhiHuan">
            <el-select :size="size" v-model="form.zhiHuan" placeholder="请选择置换意向">
              <el-option v-for="item in zhiHuan" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

        </div>


      </el-form>
      <el-divider></el-divider>
      <el-button type="primary" style="float: right;" :size='size' @click="save">保存</el-button>
    </el-row>

  </div>
</template>

<script>
  export default {
    data() {


      return {
        ershou:false,
        cars: {},
        showTree: true,
        size: 'small',
        zhiHuan: [{
            label: '是',
            value: '是'
          },
          {
            label: '否',
            value: '否'
          }
        ],
        payment: [{
            label: '全款',
            value: '全款'
          },
          {
            label: '分期',
            value: '分期'
          },
        ],
        customerState: [{
            label: '续存',
            value: '续存'
          },
          {
            label: '战败失控',
            value: '战败失控'
          },
          {
            label: '订车',
            value: '订车'
          },
          {
            label: '退订',
            value: '退订'
          },
          {
            label: '购车',
            value: '购车'
          }
        ],
        followRank: [{
            label: 'H',
            value: 'H'
          },
          {
            label: 'A',
            value: 'A'
          },
          {
            label: 'B',
            value: 'B'
          },
          {
            label: 'C',
            value: 'C'
          }
        ],
        followNum: [{
            label: '1',
            value: '1'
          },
          {
            label: '2',
            value: '2'
          },
          {
            label: '3',
            value: '3'
          },
          {
            label: '4',
            value: '4'
          },
          {
            label: '5次及以上',
            value: '5次及以上'
          }
        ],
        reachStore: [{
            label: '未邀约',
            value: '未邀约'
          },
          {
            label: '一次邀约',
            value: '一次邀约'
          },
          {
            label: '二次及以上邀约',
            value: '二次及以上邀约'
          }
        ],
        number: [{
            label: '1次',
            value: '1次'
          },
          {
            label: '2次',
            value: '2次'
          },
          {
            label: '3次',
            value: '3次'
          },
          {
            label: '4次及以上',
            value: '4次及以上'
          }
        ],
        feel: [{
            label: '一般',
            value: '一般'
          },
          {
            label: '好',
            value: '好'
          },
          {
            label: '非常好',
            value: '非常好'
          }
        ],
        huoKeTuJing: [{
            label: '共享网络平台',
            value: '共享网络平台'
          },
          {
            label: '广电（报刊）',
            value: '广电（报刊）'
          },
          {
            label: '厂家网络平台',
            value: '厂家网络平台'
          },
          {
            label: '自店网络平台',
            value: '自店网络平台'
          },
          {
            label: '店头',
            value: '店头'
          },
          {
            label: '转介绍',
            value: '转介绍'
          },
          {
            label: '销售活动',
            value: '销售活动'
          },
          {
            label: '服务活动',
            value: '服务活动'
          },
          {
            label: '异业联盟活动',
            value: '异业联盟活动'
          },
        ],
        jieQia: [{
            label: '来电',
            value: '来电'
          },
          {
            label: '来店',
            value: '来店'
          },
          {
            label: '展会',
            value: '展会'
          },
          {
            label: '外拓',
            value: '外拓'
          },
        ],
        area: [{
            label: '城区',
            value: '城区'
          },
          {
            label: '城郊',
            value: '城郊'
          },
          {
            label: '区域外',
            value: '区域外'
          }
        ],
        customerSex: [{
            label: '男',
            value: '男'
          },
          {
            label: '女',
            value: '女'
          }
        ],
        //切换新增修改显示
        toggleShow: true,
        user: '',
        form: {
          oldcars1:'',
          oldcars2:'',
          name: '',
          area: '',
          date: '',
          customerName: '',
          customerSex: '',
          phone: '',
          weiXin: '',
          customerZhiwei: '',
          jieQia: '',
          huoKeTuJing: '',
          idCard: '',
          feel: '',
          number: '',
          reachStore: '',
          followNum: '',
          followRank: '',
          customerState: '',
          payment: '',
          zhiHuan: '',
          dept: '',
          zhiwei: '',
          zhiweiId:'',
          deptId:'',
          cars: {},
          cars2: {}
        },
        //修改下拉框的值
        options: {},
        //修改下拉框选择之后存的值
        value: '',
        rules: {
          customerName: [{
            required: true,
            message: '请输入客户名称',
            trigger: 'blur'
          }],
          area: [{
            required: true,
            message: '请选择区域',
            trigger: 'change'
          }],
          customerSex: [{
            required: true,
            message: '请选择客户性别',
            trigger: 'change'
          }],
          jieQia: [{
            required: true,
            message: '请选择接洽方式',
            trigger: 'change'
          }],
          huoKeTuJing: [{
            required: true,
            message: '请选择获客途径',
            trigger: 'change'
          }],
          phone: [{
              required: false,
              trigger: 'blur',
            },
            {
              validator: function(rule, value, callback) {
                if (!value) {
                  return callback()
                }
                if (/^1[34578]\d{9}$/.test(value) == false) {
                  callback(new Error("手机号格式错误"));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            }

          ],
          idCard: [{
              required: false,
              trigger: 'blur'
            },
            {
              validator: function(rule, code, callback) {
                var city = {
                  11: "北京",
                  12: "天津",
                  13: "河北",
                  14: "山西",
                  15: "内蒙古",
                  21: "辽宁",
                  22: "吉林",
                  23: "黑龙江 ",
                  31: "上海",
                  32: "江苏",
                  33: "浙江",
                  34: "安徽",
                  35: "福建",
                  36: "江西",
                  37: "山东",
                  41: "河南",
                  42: "湖北 ",
                  43: "湖南",
                  44: "广东",
                  45: "广西",
                  46: "海南",
                  50: "重庆",
                  51: "四川",
                  52: "贵州",
                  53: "云南",
                  54: "西藏 ",
                  61: "陕西",
                  62: "甘肃",
                  63: "青海",
                  64: "宁夏",
                  65: "新疆",
                  71: "台湾",
                  81: "香港",
                  82: "澳门",
                  91: "国外 "
                };
                var tip = ""
                var pass = true
                if (!code) {
                  return callback()
                }
                if (!/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)) {
                  tip = "身份证号格式错误"
                  pass = false;
                } else if (!city[code.substr(0, 2)]) {
                  // tip = "地址编码错误"
                  tip = "身份证输入错误"
                  pass = false
                } else {
                  // 18位身份证需要验证最后一位校验位
                  if (code.length === 18) {
                    code = code.split('')
                    // ∑(ai×Wi)(mod 11)
                    // 加权因子
                    var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
                    // 校验位
                    var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
                    var sum = 0
                    var ai = 0
                    var wi = 0
                    for (var i = 0; i < 17; i++) {
                      ai = code[i]
                      wi = factor[i]
                      sum += ai * wi
                    }
                    var last = parity[sum % 11];
                    if (parity[sum % 11] != code[17]) {
                      // tip = "校验位错误"
                      tip = "身份证输入错误"
                      pass = false
                    }
                  }
                }
                if (!pass) {
                  callback(new Error(tip))
                } else {
                  callback()
                }
              },
              trigger: 'blur'
            }
          ],
          customerZhiwei: [{
            required: true,
            message: '请填写客户职业',
            trigger: 'blur'
          }],
          cars: [{
            required: true,
            message: '请选择拟购车型',
            trigger: 'change'
          }],
          followNum:[{
            required:true,
            message:'请选择跟进次数',
            trigger:'change'
          }],
          reachStore:[{
            required:true,
            message:'请选择客户到店次数',
            trigger:"change"
          }],
          followRank:[{
            required:true,
            message:'请选择跟进意向级别',
            trigger:'change'
          }],
          customerState:[{
            required:true,
            message:'请选择客户状况',
            trigger:'change'
          }]



        }
      }
    },
    methods: {

      //切换v-if
      addShow() {

        this.toggleShow = true
        emptyObj(this.form)
        this.value = '';
        this.showTree=false
        this.$nextTick(() => {
            this.showTree=true;
        });
        this.refresh()
      },
      editShow() {
        this.value = '';
        this.toggleShow = false
        emptyObj(this.form)
        this.showTree=false
        this.$nextTick(() => {
            this.showTree=true;
        });
        this.editOptions();

      },

      //查找修改下拉框的值赋给options
      editOptions() {
        this.$ajax.post("threadInput2/findByUserId", {
          userId: this.user.id
        }).then(res => {
          var result = res.data;
          this.options = result.data

        })
      },

      //保存
      save() {
        this.form.userId = this.user.id
        this.$refs.form1.validate(valid => {
          if (valid) {
            this.$ajax.post("threadInput2/save", this.form).then(res => {
              var result = res.data;
              if (result.success) {
                this.$notify({
                  title: '提示',
                  message: '数据保存成功',
                  type: 'success',
                  position: 'bottom-right'
                });
                emptyObj(this.form)
                this.editOptions();
                this.value = '';
                this.refresh()
              }
            })

          }
        })
      },


      //选择下拉框
      editChange() {
        this.$ajax.post("threadInput2/findById", {
          id: this.value
        }).then(res => {
          var result = res.data;
          this.form = result.data;
            if(result.data.carsId){
                 var cars = result.data.carsId.split(',').map(Number)
                 var cars1 = []
                 for (var arrInt in cars) {
                     cars1.push(cars[arrInt])
                 }
                 this.$set( this.form,'cars',cars1);
            }
            if(result.data.cars2Id){
                 var cars = result.data.cars2Id.split(',').map(Number)
                 var cars1 = []
                 for (var arrInt in cars) {
                     cars1.push(cars[arrInt])
                 }
                 this.$set( this.form,'cars2',cars1);
            }
         this.showTree=false
         this.$nextTick(() => {
             this.showTree=true;
         });
          this.$set( this.form,'customerName',result.data.thread.customerName);
             this.$set( this.form,'id',result.data.thread.id);
       this.refresh()
        })
      },

      //点击下拉框×
      //点击下拉框×
      qingkong() {
        this.value = '';
      },
      getNowTime() { //得到当天时间
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth(); //得到月份
        var date = now.getDate(); //得到日期
        var hour = now.getHours(); //得到小时
        var min = now.getMinutes(); //得到分钟
        var seconds = now.getSeconds(); //得到秒钟
        month = month + 1;
        month = month.toString().padStart(2, "0");
        date = date.toString().padStart(2, "0");
        var defaultDate = year + '-' + month + '-' + date + ' ' + hour + ':' + min + ':' + seconds;
        this.form.date = new Date(defaultDate);
      },
      getuser() { //得到员工信息
        this.$ajax.post('user/getuser', {}).then(res => {
          var result = res.data
          this.form.zhiwei = result.data.zhiwei.name
          this.form.dept=result.data.zhiwei.dept.name
          this.form.zhiweiId=result.data.zhiwei.id
          this.form.deptId=result.data.zhiwei.dept.id
          this.user = result.data
          if("二手车部"===result.data.deptName){
            this.ershou=true
          }
        })
      },
      getCar() { //获取车型
        this.$ajax.post('carsOrder/carType', {}).then(res => {
          var result = res.data
          this.$set(this, "cars", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })

      },

      refresh() {
        this.getNowTime()
        this.getuser()
        this.form.name = window.sessionStorage.getItem('name');
      }

    },
    created() {
      this.getCar()
      this.refresh()

    }

  }



  function emptyObj(obj) {
    if (obj.file) {
      obj.file = ""
    }
    if (obj.date) {
      obj.date = ""
    }
    if(obj.cars){
      obj.cars=""
    }
    if(obj.cars2){
      obj.cars2=""
    }
    if(obj.oldcars1){
      obj.oldcars1=""
    }
    if(obj.oldcars2){
      obj.oldcars2=""
    }
    for (var key in obj) {
      var o = obj[key];
      if (o instanceof Object) {
        emptyObj(o);
      } else {
        obj[key] = '';
      }
    }
  }
</script>

<style>
</style>
